package com.zjl.itextpdf;

import com.zjl.itextpdf.utils.HtmlToPdfUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.*;

@Slf4j
public class PdfTest {

    public static void main(String[] args) throws IOException {
        long startTime = System.currentTimeMillis();
        //       html文件所在相对路径
        // D:\idea-workspace\mybatis-parent\springboot-mybatis-plus\src\main\resources\templates\pdf.html
        String htmlFile = "springboot-mybatis-plus/src/main/resources/templates/pdf.html";
        //       pdf文件存储相对路径
        String pdfFile = "springboot-mybatis-plus/src/main/resources/templates/x6.pdf";
        //        自定义水印
        String waterMarkText =  "哇迈k";
        InputStream inputStream = new FileInputStream(htmlFile);
        OutputStream outputStream = new FileOutputStream(pdfFile);
        //微软雅黑在windows系统里的位置如下，linux系统直接拷贝该文件放在linux目录下即可
        //        String fontPath = "src/main/resources/font/STHeiti Light.ttc,0";
        String fontPath = "springboot-mybatis-plus/src/main/resources/font/simhei.ttf";
        HtmlToPdfUtils.convertToPdf(inputStream, waterMarkText, fontPath, outputStream);
        log.info("转换结束，耗时：{}ms",System.currentTimeMillis()-startTime);
    }
}
